<?php

namespace common\db;

/**
 * The redis connection class is used to establish a connection to a [redis](http://redis.io/) server.
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
class RedisConnection extends \yii\redis\Connection {

    public $max_delay_time = 31536000;

    public function setArray($name, $data) {
        $params = [
            $name
        ];
        foreach ($data as $k => $v) {
            $params[] = $k;
            $params[] = $v;
        }
        return call_user_func_array(array($this, "hmset"), $params);
    }

    public function getArray($key, $field = null) {
        if ($field == null) {
            $data = $this->hgetall($key);
        }
        return $this->hget($key, $field);
    }

}
